package cn.znzz.cjm.order.controller;

import cn.znzz.cjm.basic.util.AjaxResult;
import cn.znzz.cjm.basic.util.LoginContext;
import cn.znzz.cjm.basic.util.PageList;
import cn.znzz.cjm.order.domain.AdoptOrder;
import cn.znzz.cjm.order.query.AdoptOrderQuery;
import cn.znzz.cjm.order.service.IAdoptOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/adoptOrder")
public class AdoptOrderController {

    @Autowired
    private IAdoptOrderService adpotOrderService;

    @PostMapping("/submit")
    public AjaxResult submit(@RequestBody Map<String,Object> params, HttpServletRequest request){

       try{
            String payData = adpotOrderService.submit(params,LoginContext.getCurrentLogin(request));
            return AjaxResult.me().setResultObj(payData);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("下单失败！"+e.getMessage());
        }

    }
    @PostMapping("/user")
    public PageList<AdoptOrder> queryUserOrder
            (@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adpotOrderService.queryUserOrder(query,LoginContext.getCurrentLogin(request));
    }
    @PostMapping("/admin")
    public PageList<AdoptOrder> queryAdmin
            (@RequestBody AdoptOrderQuery query, HttpServletRequest request){
        return adpotOrderService.queryAdmin(query,LoginContext.getCurrentLogin(request));
    }

    @GetMapping("/{id}")
    public AdoptOrder queryById(@PathVariable("id") Long id){
        return adpotOrderService.queryById(id);
    }
}
